package com.yitiao.designmodel.behave.chain.ext;

import java.util.ArrayList;
import java.util.List;

public class FilterChain implements Filter{
    List<Filter> filters =new ArrayList<>();
    int index = 0;
    Target target;

    public void setTarget(Target target) {
        this.target = target;
    }

    public void addFilter(Filter filter){
        filters.add(filter);
    }

    @Override
    public void doFilter(Requset requset, Response response, FilterChain chain) {
        if (index < filters.size()){
            Filter filter = filters.get(index);
            index ++;
            filter.doFilter(requset,response,chain);
        }else {
            target.hello();
        }
    }
}
